package com.clps.algorithm03.冒泡排序;

import java.util.Arrays;

public class demo01 {
    public static void main(String[] args) {
        demo01 demo01 = new demo01();
        //int[] arr ={10,9,8,7,6,5,4,3,2,1};
        int[] arr ={9,10,11,12,13,14};
        demo01.sort(arr);

    }

    public void sort(int[] nums){
        int length = nums.length;
        for (int i = 1; i <length ; i++) {
            System.out.println("111Arrays.asList(nums) = " + Arrays.toString(nums));
            for (int j = 0; j <length-i ; j++) {
                System.out.println("222Arrays.asList(nums) = " + Arrays.toString(nums));
                //如果当前元素大于它的下一个元素,则交换他们两个的值
                if(nums[j]>nums[j+1]){
                    swap(nums,j,j+1);
                    System.out.println("333Arrays.asList(nums) = " + Arrays.toString(nums));
                }
            }
        }
    }

    private void swap(int[] nums, int j, int i) {
        int tmp= nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }


}

